package com.sz.controller;

import com.sz.model.PageBean;
import com.sz.model.PageBeanType;
import com.sz.model.QuestionAnswer;
import com.sz.model.QuestionType;
import com.sz.service.IPageBeanAnswer;
import com.sz.service.IProblemType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/problem")
public class ProblemController {

    @Autowired
    private IProblemType iProblemType;

    //查询所有的问题类型;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

//    @GetMapping("/getAllQuestion")
//    public PageBeanType<QuestionType> getAllQuestion(int index, int size) {
//        return iProblemType.getAllQuestion(index, size);
//
//    }

    //带分页查询一种类型的问题答案
    @Autowired
    private IPageBeanAnswer iPageBeanAnswer;

//    @GetMapping("/getAllAnswer")
//    public PageBean<QuestionAnswer> getAllAnswer(int index, int size, int pkKid) {
//        return iPageBeanAnswer.getAllAnswer(index, size, pkKid);
//    }

    @PostMapping("/getQuestion")
    public PageBeanType<QuestionType> getQuestion(int index, int size, String question){
        System.out.println("question = " + question);
        if (question.isEmpty()) {
            return iProblemType.getAllQuestion(index, size);
        } else {
            return iProblemType.getQuestion(index,size,"%" + question + "%");
        }

    }

    @PostMapping("/getAnswer")
    public PageBean<QuestionAnswer> getAnswer(int index, int size, int pkKid, String answer){
        PageBean<QuestionAnswer> list = null;
        if (answer.isEmpty()){
            list = iPageBeanAnswer.getAllAnswer(index, size, pkKid);
        }else {
            System.out.println("answer = " + answer);
            list = iPageBeanAnswer.getAnswer(index, size, "%" + answer + "%");
        }
        return list;

    }
}
